package servlets;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import JurisPro.Sistema;
import JurisPro.modelo.Processo;

/**
 * Servlet implementation class pdf
 */
public class pdf extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public pdf() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
			String numPro = request.getParameter("num");
			Processo processo = Sistema.getInstance().buscarProcessoPorNum(numPro);

	        ServletOutputStream op  = response.getOutputStream();
	     
	        response.setContentType("application/pdf");
	        response.setContentLength( (int)processo.getPdf().length);
	        
	        op.write(processo.getPdf());
	       
	        op.flush();
	        op.close();
	       /* request.setAttribute("prodetalhe", Sistema.getInstance().buscarProcessoPorNum(numPro));
			request.setAttribute("eventospro", Sistema.getInstance().ListarEventosDoProcesso(numPro));
			request.setAttribute("titulo", "Jurispro - Detalhes de Processo");
			RequestDispatcher dispache = request.getRequestDispatcher("pages/detalhe.jsp");
			dispache.forward(request, response);*/
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
